package com.skywork.service;

import java.util.List;

import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.skywork.domain.Channel;
import com.skywork.domain.base.ActiveFlag;
import com.skywork.service.base.BaseService;

@Service
@CacheConfig(cacheNames = "channel")
public class ChannelService extends BaseService<Channel> {

//	@Autowired
//	private ChannelMapper channelMapper;
	@Transactional
	@CacheEvict(value= {"channelById","channel"},allEntries=true)
	public Channel save(Channel channel){
		if(channel.getId()==null){
			insertUseGeneratedKeys(channel);
		}else{
			updateByPrimaryKey(channel);
		}
		return channel;
	}
	
	public List<Channel> findAll(Channel channel){
		//PageHelper.startPage(1, 10);
		return select(channel);
	}
	
	public Channel findByCode(String code){
		Channel channel = new Channel();
		channel.setActiveFlag(ActiveFlag.ACTIVE);
		channel.setCode(code);
		return selectOne(channel);
	}
}
